﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cesave.Infrastructure.CrossCutting.Logging;
using Cesave.Infrastructure.CrossCutting.IoC;
using Cesave.Domain.PermisosModule.Contracts.Variedades;
using System.ServiceModel;
using Cesave.DistributedServices.Core.ErrorHandlers;

namespace Cesave.DistributedServices.PermisosModule
{
	public partial class PermisosModuleService
	{
		#region IPermisosModuleService Members

		/// <summary>
		/// 
		/// </summary>
		/// <param name="variedad"></param>
		public void AddVariedad(Domain.PermisosModule.Entities.Variedad variedad)
		{
			try
			{
				IVariedadService variedadService = IoCFactory.Resolve<IVariedadService>();
				variedadService.AddVariedad(variedad);
			}
			catch (Exception ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				throw new FaultException<ServiceError>(ServiceError.Factory(ex.Message));
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="variedad"></param>
		public void ChangeVariedad(Domain.PermisosModule.Entities.Variedad variedad)
		{
			try
			{
				IVariedadService variedadService = IoCFactory.Resolve<IVariedadService>();
				variedadService.ChangeVariedad(variedad);
			}
			catch (Exception ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);
				
				throw new FaultException<ServiceError>(ServiceError.Factory(ex.Message));
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="cultivoGuid"></param>
		/// <returns></returns>
		public List<Domain.PermisosModule.Entities.Variedad> FindVariedadesByCultivo(Guid cultivoGuid)
		{
			try
			{
				IVariedadService variedadService = IoCFactory.Resolve<IVariedadService>();
				return variedadService.FindVariedadesByCultivo(cultivoGuid);
			}
			catch (Exception ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				throw new FaultException<ServiceError>(ServiceError.Factory(ex.Message));
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="cultivoGuid"></param>
		/// <param name="status"></param>
		/// <returns></returns>
		public List<Domain.PermisosModule.Entities.Variedad> FindVariedadesByCultivoAndStatus(Guid cultivoGuid, bool status = true)
		{
			try
			{
				IVariedadService variedadService = IoCFactory.Resolve<IVariedadService>();
				return variedadService.FindVariedadesByCultivoAndStatus(cultivoGuid, status);
			}
			catch (Exception ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				throw new FaultException<ServiceError>(ServiceError.Factory(ex.Message));
			}
		}

		#endregion
	}
}
